/**
 * 
 */
package com.cqan.account.dao;

import java.util.List;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.cqan.account.entity.Authority;
import com.cqan.account.entity.Authority.AuthType;
import com.cqan.dao.hibernate.HibernateDao;

/**
 * @Description TODO
 * @author slaton.wu@gmail.com
 * @date 2012-6-29下午7:23:21
 * 
 */
@Repository("authorityDao")
public class AuthorityDao extends HibernateDao<Authority, Long> {

	/**
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Authority> getMenus() {
		return getSession().createCriteria(Authority.class)
				.add(Restrictions.eq("enabled", true))
				.add(Restrictions.eq("authType", AuthType.MENU)).addOrder(Order.desc("updateTime")).list();
	}

	@SuppressWarnings("unchecked")
	public List<Authority> getTopMenus() {
		return getSession().createCriteria(Authority.class)
				.add(Restrictions.eq("enabled", true)).add(Restrictions.eq("authType", AuthType.MENU)).addOrder(Order.desc("updateTime")).add(Restrictions.isNull("parent")).list();
	}

}
